package com.xjtu.config;

import io.swagger.annotations.ApiOperation;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;


/**
 * Swagger配置类
 */
@Configuration
@EnableSwagger2
public class SwaggerConfig {

    //API页面上半部分展示信息
    private ApiInfo apiInfo(){
        return new ApiInfoBuilder()
                .title("聊天呼叫系统接口文档")
                .description("medical-care")
                .contact(new Contact("XJTU", null, "yaachou@qq.com"))
                .version("1.0")
                .build();
    }

    @Bean
    public Docket createRestAPI(){
        return new Docket(DocumentationType.SWAGGER_2)
                //是否开启swagger
                .enable(true)

                //分组名称
                .groupName("聊天呼叫")

                //basePath
                .pathMapping("/")

                //API元信息设置在响应中
                .apiInfo(apiInfo())

                //接口调试地址
                //.host("api")

                //支持的通信协议集合
                //.protocols(new HashSet())

                //选择接口发布
                .select()
                //.apis(RequestHandlerSelectors.basePackage("com.xjtu.controller"))
                .apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class))
                .paths(PathSelectors.any())
                .build();
    }

}